﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using StudentWeb.BLL;
using Newtonsoft.Json.Linq;
using StudentWeb.Common;

namespace StudentWeb.Api.Controllers
{
    public class XhVipController : ApiController
    {
        XhVipBO _xhvipBO = new XhVipBO();
        #region vip用户 登录
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost]
        public IHttpActionResult Login([FromBody]JObject obj)
        {
            dynamic model = obj;
            string XhVipName = model.XhVipName ?? "";
            string XhVipPassword = model.XhVipPassword ?? "";
            if (string.IsNullOrEmpty(XhVipName) || string.IsNullOrEmpty(XhVipPassword))
            {
                return Json(new Result(ResultCode.Fail, "用户名或密码不能为空"));
            }
            try
            {

                var result = _xhvipBO.Login(XhVipName, XhVipPassword);
                return Json(result);
            }
            catch (Exception ex)
            {
                return Json(new Result(ResultCode.Fail, ex.Message));
            }
        }
        #endregion


        #region vip注册 注册
        /// <summary>
        /// 教师注册 注册
        /// </summary>
        /// <param name="token"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        [HttpPost]
        //[ValidToken]
        public IHttpActionResult RegisterTeacherInfo(string token, [FromBody]JObject obj)
        {
            dynamic model = obj;
            if (model == null) return Json(new Result(ResultCode.Fail, "缺少参数"));
            try
            {
                var result = _xhvipBO.SaveXhVipInfo(model, 0);
                return result ? Json(new Result()) : Json(new Result(ResultCode.Fail, "保存失败"));
            }
            catch (Exception ex)
            {
                return Json(new Result(ResultCode.Fail, ex.Message));
            }
        }
        #endregion
    }

}